<link href="__CDN__/assets/css/app_new.css" rel="stylesheet">
<style>
    .BalanceDetail ul.invite-f-2 {
        height: 0rem;
    }
    .isVisited a{
        color: #ff7300;
        border: 1px solid #ff7300;
        border-radius: 6px;
        width: 1.2rem;
        height: 0.52rem;
        font-size: 0.26rem;
        text-align: center;
        line-height: 0.52rem;
    }
</style>
<div class="all-container">
    <div class="login-register-header">
        <div class="back-btn"><a href="javascript:history.go(-1)"><img src="__CDN__/map/images/return@2x.png" alt="返回"/></a></div>
        <div>
            <div class="invite-header-c d-flex">
                <span class="add-agent-title">财务管理</span>
            </div>
        </div>
    </div>
    <div class="am-tabs member-list-f" data-am-tabs="{noSwipe: 1}" id="doc-tab-demo-1">
        <ul class="am-tabs-nav am-nav am-nav-tabs d-flex">
            <li class="am-active"><a href="javascript: void(0)" onclick="onclik(1)">收益记录</a></li>
            <li><a href="javascript: void(0)" onclick="onclik(2)">提现记录</a></li>
        </ul>
        <div class="am-tabs-bd">
            <div class="am-tab-panel am-active">
                <div class="member-list-f1">
                    <div class="d-flex">
                        <span>
                            <input type="text" id="my-start" style="width:60%;background-color:white" class="am-form-field" placeholder="选择日期" data-am-datepicker readonly required />
                        </span>


                    </div>
                    <div class="d-flex isVisited">
                        <div>
                            <p>我的收益</p>
                            <span id="money1">0.00</span>
                        </div>
                        <a href="JavaScript:history.go(0)" onclick="moneyonclick()">月账单</a>
                    </div>
                </div>
                <div class="BalanceDetail"  >
                <ul class="invite-f-2 member-list-ul" id="ul1" style=" height: 40vh;">

                </ul>
                </div>
            </div>
            <div class="am-tab-panel">
                <div class="member-list-f1">
                    <div class="d-flex">
                        <span>
                            <input type="text" id="my-start1" style="width:60%;background-color:white" class="am-form-field" placeholder="选择日期" data-am-datepicker readonly required />
                        </span>


                    </div>
                    <div class="d-flex isVisited">
                        <div>
                            <p>我的余额</p>
                            <span id="money2">0.00</span>
                        </div>
                        <span onclick="moneyonclick()">月账单</span>
                    </div>
                </div>
                <div class="BalanceDetail"  >
                    <ul class="invite-f-2 member-list-ul" id="ul2" style=" height: 50vh;" >
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="__CDN__/assets/js/zepto.min.js"></script>
<script type="text/javascript" src="__CDN__/assets/js/PullToRefresh.min.js"></script>
<script>

    var date='';
    var n=0,flag=true;
    var idname='1';
    var type=1;
    $('#my-start').datepicker().
    on('changeDate.datepicker.amui', function(event) {
        date=event.target.defaultValue;
        re_ajax(1,date,type,type);
        $(this).datepicker('close');
    });
    $('#my-start1').datepicker().
    on('changeDate.datepicker.amui', function(event) {
        date=event.target.defaultValue;
        re_ajax(1,date,type,type);
        $(this).datepicker('close');
    });
    function onclik(val) {
        type=val;
        re_ajax(1,0,val,val);

    }

    function  moneyonclick() {
        window.location.reload()
        re_ajax(1,0,type,type);
    }






    var refreshBox=new PullToRefresh({
        // container:".BalanceDetail",
        pull: {
            callback: function() {
                setTimeout(function() {
                    n = 0;
                    re_ajax(n);
                    refreshBox.endPullRefresh(false);
                }, 1000);
            }
        },
        up:{
            callback:function(){
                setTimeout(function(){
                    n++
                    re_ajax(n,date,idname,type)
                },1000)
            }
        }
    })
    function re_ajax(page,date,idname,type){
        $.ajax({
            type:"POST",
            url:"{:url('user/financial')}",
            dataType:"json",
            data:{
                page:page,
                date:date,
                type:type

            },
            success:function(data){


                var html='';


                if(page==1||page==0){
                    $('#ul'+idname).html('');
                }
                data.data.forEach(function (v) {
                    var shop_res_point='';
                    if(type==1){
                        shop_res_point='商家让利比'+v.shop_res_point+'%';
                    }
                    var name='';
                    var namevar='';
                    if (v.money_type == 1) {
                        name = "二级个权分润";
                        namevar='+';
                    } else if (v.money_type == 2) {
                        name = "商家分润";
                        namevar='+';
                    } else if (v.money_type == 3) {
                        name='服务商分润';
                        namevar='+';
                        // var server={$user.server_type};
                        // if(server==1){
                        //     name='省代理';
                        // }else if(server==2){
                        //     name='市代理';
                        // }else if(server==3){
                        //     name='区代理';
                        // }
                    }else if(v.money_type==4) {
                        name='分红';
                        namevar='+';
                    }else if(v.money_type==5) {
                        name='股权';
                        namevar='+';
                    }else if(v.money_type==7){
                        name='提现';
                        namevar='-';
                    }else if(v.money_type==8) {
                        if(v.user_id==v.playUser_id){
                            name='消费贡献值';
                            namevar='+';
                        }else{
                            name='二级贡献值';
                            namevar='+';
                        }
                    }else if(v.money_type==9) {
                        name='消费余额';
                        namevar='-';
                    }else if(v.money_type==10){
                        name='商家应收款';
                        namevar='+';
                    }else if(v.money_type==11){
                        name='二级个权分佣';
                        namevar='+';
                    }else if(v.money_type==12){
                        name='消费金额';
                        namevar='-';
                    }else if(v.money_type==13){
                        name='跨商家收益';
                        namevar='+';
                    }
                    html+='<li>';
                    html+='<div>';
                    html+='<div>';
                    html+='<em>'+name+'</em>';
                    if(v.money_type==7){
                        if(v.status==1){
                            html+='<span class="member-list-font">审核中</span>';
                        }else if(v.status==2){
                            html+='<span class="member-list-font">审核通过</span>';
                        }else if(v.status==3){
                            html+='<span class="member-list-font">审核失败</span>';
                        }

                    }else if(v.money_type==4){
                        html+='<span class="member-list-font"></span>';
                    }else if(v.money_type==8){
                        if(v.user_id==v.playUser_id){
                            html+='<span class="member-list-font">会员ID: '+v.user_id+'</span>';
                        }else{
                            html+='<span class="member-list-font">来源会员ID: '+v.playUser_id+'</span>';
                        }
                    }else if(v.money_type==5){
                        html+='<span class="member-list-font"></span>';
                    }else if(v.money_type==11){
                        html+='<span class="member-list-font"></span>';
                    }else{
                        html+='<span class="member-list-font">来源会员ID: '+v.playUser_id+'</span>';
                    }

                    html+='</div>';
                    html+='<span>'+v.createtime+'</span></span>';
                    html+='</div>';
                    html+='<span>'+namevar+v.money+'</span>';
                    html+='</li>';
                })

                if(page==1){
                    $('#ul'+idname).html('');
                }
                $('#money'+idname).html(data.noney)
                $('#ul'+idname).append(html);
                if(html==''){
                    refreshBox.endPullRefresh(false)
                }else{
                    refreshBox.endPullRefresh(true)
                }
            },
            error:function(jqXHR){
                console.log("Error: "+jqXHR.status);
            }
        });
    }

</script>